import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
    page = "/msg-push-service/msgTemplate/pageMsgTemplate",
    list = "/msg-push-service/template/listAll",
    save = "/msg-push-service/msgTemplate/saveMsgTemplate",
    edit = "/msg-push-service/msgTemplate/updateMsgTemplate",
    updateTemplateStatus = "/msg-push-service/msgTemplate/updateTemplateStatus",
    get = "/msg-push-service/msgTemplate/getMsgTemplate",
    delete = "/msg-push-service/msgTemplate/deleteMsgTemplate",
    deleteBatch = "/msg-push-service/msgTemplate/deleteBatchMsgTemplate",
    listTemplateByTemplateId = "/msg-push-service/msgTemplate/listTemplateByTemplateId",
    listChannel = "/msg-push-service/msgTemplate/listChannel",
}

/**
 * 查询列表
 * @param params
 */
export const pageTemplate = (params) => {
    return defHttp.get({url: Api.page, params});
}

export const listTemplate = (params) => {
    return defHttp.get({url: Api.list, params});
}

export const listTemplateByTemplateId = (params) => {
    return defHttp.get({url: Api.listTemplateByTemplateId, params});
}

/**
 * 查询全部渠道
 * @param params
 */
export const listChannel = () => {
    return defHttp.get({url: Api.listChannel, params: {}});
  }
  

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateTemplate = (params, isUpdate) => {
    let url = isUpdate ? Api.edit : Api.save;
    return defHttp.post({url: url, params});
}

export const updateTemplateStatus = (params) => {
    return defHttp.post({url: Api.updateTemplateStatus, params}, { joinParamsToUrl: true});
}

/**
 * 查询详情
 * @param params
 */
export const getTemplate = (params) => {
    return defHttp.get({url: Api.get, params});
}

/**
 * 删除
 * @param params
 */
export const deleteTemplate = (params,handleSuccess) => {
    return defHttp.delete({url: Api.delete, data: params}, {joinParamsToUrl: true}).then(()=>{
        handleSuccess();
    });
}

/**
 * 批量删除
 * @param params
 */
export const batchDeleteTemplate = (params, handleSuccess) => {
    Modal.confirm({
        title: '确认删除',
        content: '是否删除选中数据',
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
            return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
                handleSuccess();
            });
        }
    });
}
